<?php
add_action( 'restrict_manage_posts', 'cpx_admin_filter_storename_restrict_manage_posts' );
/**
 * First create the dropdown
 * make sure to change store to the name of your custom post type
 */
function cpx_admin_filter_storename_restrict_manage_posts(){
    $type = 'post';
    if (isset($_GET['post_type'])) {
        $type = $_GET['post_type'];
    }

    //only add filter to post type you want
    if ('coupon' == $type){
        //change this to the list of values you want to show
        //in 'label' => 'value' format
        global $wpdb;
        $qr = "select id,post_title from {$wpdb->posts} where post_type = 'store' and post_status = 'publish' order by post_title";
        $rs = $wpdb->get_results($qr);
        
        $arr_storename = array();
        foreach ($rs as $st) {
            $arr_storename[$st->post_title] = $st->id;
        }
        ?>
        <select name="ADMIN_FILTER_FIELD_VALUE">
        <option value=""><?php _e('Filter By Store name ', 'couponx'); ?></option>
        <?php
            $current_v = isset($_GET['ADMIN_FILTER_FIELD_VALUE'])? $_GET['ADMIN_FILTER_FIELD_VALUE']:'';
            foreach ($arr_storename as $label => $value) {
                printf
                    (
                        '<option value="%s"%s>%s</option>',
                        $value,
                        $value == $current_v? ' selected="selected"':'',
                        $label
                    );
                }
        ?>
        </select>
        <?php
    }
}

add_filter( 'parse_query', 'cpx_store_name_filter' );
/**
 * if submitted filter by post meta
 * 
 * make sure to change META_KEY to the actual meta key
 * and store to the name of your custom post type
 */
function cpx_store_name_filter( $query ){
    global $pagenow;
    $type = 'post';
    if (isset($_GET['post_type'])) {
        $type = $_GET['post_type'];
    }
    if ( 'coupon' == $type && is_admin() && $pagenow=='edit.php' && isset($_GET['ADMIN_FILTER_FIELD_VALUE']) && $_GET['ADMIN_FILTER_FIELD_VALUE'] != '') 
    {
//        if($_GET['ADMIN_FILTER_FIELD_VALUE'] == 'filter_empty_store_des')
//            add_filter('posts_where','filter_empty');
//        if($_GET['ADMIN_FILTER_FIELD_VALUE'] == 'filter_full_store_des')
//            add_filter('posts_where','filter_full');
        $st_id = $_GET['ADMIN_FILTER_FIELD_VALUE'];
        if($st_id != '')
        {
            $query->query_vars['meta_key'] = 'store_coupon_metadata';
            $query->query_vars['meta_value'] = $st_id;
        }
    }
}

//function filter_empty($where)
//{
//    global $wpdb;
//    $where.= " AND {$wpdb->posts}.post_content = ''";
//    return $where;
//}
//function filter_full($where)
//{
//    global $wpdb;
//    $where.= " AND {$wpdb->posts}.post_content != ''";
//    return $where;
//}